﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Windows;

namespace UIControls
{

    public class TimeCell : INotifyPropertyChanged
    {
        public TimeSpan TimeSpan { get; set; }
        public int HourNumber { get; set; }
        public int MinuteNumber { get; set; }
        public int SecondNumber { get; set; }


        public TimeCell(int h, int m, int s)
        {
            HourNumber = h;
            MinuteNumber = m;
            SecondNumber = s;
            this.TimeSpan = TimeSpan.FromSeconds(m * 60 + s);
        }

        public TimeCell()
        {

        }
        public TimeCell(TimeSpan span)
        {
            this.TimeSpan = span;
        }

        public string Time
        {
            get
            {
                if (this.TimeSpan.TotalSeconds >= 0)
                {
                    string value = this.TimeSpan.ToString();

                    string h = (value.ToString().Substring(0, 2));
                    string m = (value.ToString().Substring(3, 2));

                    return h + ":" + m;
                }
                else
                {
                    return "不设置";
                }

            }
        }

        public override string ToString()
        {
            return this.Time;
        }

        public event PropertyChangedEventHandler PropertyChanged;

        private void OnPropertyChanged(string name)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(name));
        }

    }



    #region RoutedEvent
    /// <summary>
    /// Routed event args for the DateSelectedChanged
    /// </summary>
    public class DateSelectedChangedRoutedEventArgs : RoutedEventArgs
    {
        /// <summary>
        /// Constructor for the event args
        /// </summary>
        /// <param name="routedEvent">The event for which the args will be passed</param>
        public DateSelectedChangedRoutedEventArgs(RoutedEvent routedEvent)
            : base(routedEvent) { }

        /// <summary>
        /// Gets or sets the new date that was set
        /// </summary>
        public TimeSpan NewDate { get; set; }

        /// <summary>
        /// Gets or sets the old date that was set
        /// </summary>
        public TimeSpan OldDate { get; set; }
    }

    /// <summary>
    /// Delegate for the DateSelectedChanged event
    /// </summary>
    /// <param name="sender">The object that raised the event</param>
    /// <param name="e">Event arguments for the DateSelectedChanged event</param>
    public delegate void DateSelectedChangedEventHandler(object sender, DateSelectedChangedRoutedEventArgs e);
    #endregion
}
